<#include "/common/_layout.html">
<#assign pageJavascript>
<script type="text/javascript" src="/assets/rabbit/jquery.imgup.js"></script>
<script type="text/javascript">
$(function(){
	$("#form1").Validform({
		tiptype:4,
		beforeSubmit:function(curform){
			var para = $(curform).serializeObject();
			$.extend(para,{"id":"${(device.id)!}"});
			var loadIndex = layer.load();
			$.post("/admin/device/device/save?v="+Math.random(),para,function(data){
	           if (data.msg == 'success') {
	        	   layer.alert('保存成功！',{icon: 6},function(index){
	        		   layer.close(index);
	        		   window.location="/admin/device/device";
	        	   });
	           }
		       else {layer.msg('保存失败！', {icon: 5});}
	           layer.close(loadIndex);
			});
			return false;	
		}
	});
	$("#imgbtn").click(function(){
		alert($(".imgbb").imgup('getImgs'));
	});
	$(".imgbb").imgup({muti:true,imgs:[]});
	$("#id").blur(function(){
		var para = $("#id").val();
		$.post("/admin/device/device/macajax?v="+Math.random()+"&mac="+para,function(data){ 
			if (data.res == 0) {
		    	$(".bot .Validform_checktip").removeClass("Validform_right");
		    	$(".bot .Validform_checktip").addClass("Validform_wrong");
		    	$(".bot .Validform_checktip").text("mac已存在!");
		    	$("#sub").attr('type','button');
		    	$("#id").focus();
	           }
			else{
				$("#sub").attr('type','submit');
			}
			});
			return false;	
	});
});
</script>
</#assign>
<@layout pageTitle="设备管理" pageJavascript=pageJavascript pageCss=pageCss>	
<h3 class="page-header">设备管理</h3>	
<form id = "form1" class="form-horizontal">
 <div class="form-group">
    <label for="id" class="col-sm-2 control-label">mac地址</label>
    <div class="col-xs-10 col-sm-5">
    <input type="hidden" id="id" value="${(item.id)!}" name="device.id">
      <input type="text" id="id" value="${(item.id)!}" name="device.id" datatype="s12-16" <#if item??> disabled</#if> class="form-control">
    </div>
  </div>  
  <div class="form-group">
    <label for="sn" class="col-sm-2 control-label">SN码</label>
    <div class="col-xs-10 col-sm-5">
      <input type="text" id="sn" name="sn" value="${(item.sn)!}" datatype="s2-40" class="form-control">
    </div>
  </div>
  <div class="form-group">
    <label for="remark" class="col-sm-2 control-label">说明</label>
    <div class="col-xs-10 col-sm-5">
      <input type="text" id="remark" name="remark" value="${(item.remark)!}" datatype="s0-100" class="form-control">
    </div>
  </div>
  <div class="form-group">
    <label for="pid" class="col-sm-2 control-label">产品</label>
    <div class="col-xs-10 col-sm-5">
    	<#if item??>
    		<input type="text"  value="${(product.pname)!}"  disabled class="form-control">
    	<#else>
	    	<select name="pid" id="pid" class="form-control">
			<#if plist??>
			<#list plist as data>
			<option value="${data.id}">${data.pname}</option>
			</#list>
			</#if>	
			</select>
		</#if>
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-success" id="sub">提交</button>
      <a href="/admin/device/device" class="btn btn-default">取消</a>
    </div>
  </div>
</form>
</@layout>